#include "piece.h"

//-------------------------------------------------------------------------------------------
Piece::Piece() : Polygon()
{
	this->color = Qt::white;
}

//-------------------------------------------------------------------------------------------
Piece::Piece(QColor color) : Polygon()
{
	this->color = color;
}

//-------------------------------------------------------------------------------------------
Piece::~Piece()
{
}

//-------------------------------------------------------------------------------------------
void Piece::setColor(QColor color)
{
	this->color = color;
}

//-------------------------------------------------------------------------------------------
void Piece::draw(QPainter *painter, int mode)
{
	painter->setRenderHint(QPainter::Antialiasing, true);
	QVector<QPointF> points = this->getVertexes().toVector();
	if (mode == 0){
		painter->setBrush(QBrush(color, Qt::SolidPattern));
		painter->setPen(QPen(Qt::black, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
		painter->drawPolygon(points.constData(), points.count());
	}else if (mode == 1){
			painter->setPen(QPen(Qt::red, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
			painter->drawPolyline(points.constData(), points.count());
		}else{
			painter->setBrush(QBrush(Qt::lightGray, Qt::SolidPattern));
			painter->setPen(QPen(Qt::black, 0.5, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
			for (int i = 0; i < this->getVertexes().size(); i++){
				painter->drawEllipse((int)this->getVertexes().at(i).x()-5,(int)this->getVertexes().at(i).y()-5,10,10);
			}
		}
}

//-------------------------------------------------------------------------------------------
QColor Piece::getColor()
{
	return this->color;
}

